package gui;

import java.util.ArrayList;
import java.util.List;

import javax.swing.JPanel;

import model.Location;
import dao.Dao;

/**
 * @author Alexander Shidlovsky
 */
public class StockPanel extends JPanel implements Updatable {

	private int width;
	private int height;

	private List<StackPanel> stackList = new ArrayList<StackPanel>();

	public StockPanel(int width, int height) {
		setLayout(null);
		this.width = width;
		this.height = height;
		setSize(600, 500);
		setLocation(10, 10);

		List<Location> locations = Dao.getInstance().getLocations();
		for (int i = 0; i < this.height; i++) {
			for (int j = 0; j < this.width; j++) {
				StackPanel pnl = new StackPanel(locations.get(i * height + j));
				add(pnl);
				pnl.setLocation(getWidth() / width * j + 5, getHeight()
						/ height * i + 10);
				stackList.add(pnl);
			}
		}

	}

	@Override
	public void updateView() {

		for (StackPanel sp : stackList) {
			sp.updateView();
		}
	}
}
